<template>
	<view class="box">
		<!-- <u-navbar title="阀贸通" placeholder autoBack border></u-navbar> -->
		<view class="title flex flex-ai-c">
			<view></view>
			<text>基本资料</text>
		</view>
		<view class="list">
			<u-form :model="form" :rules="rules" ref="uForm" :errorType="errorType">
				<u-form-item label="店铺名称*" prop="shopName" label-width="200rpx">
					<u-input v-model="form.shopName" placeholder="请输入店铺名称" type="text" />
				</u-form-item>
				<u-form-item label="企业名称*" prop="enterpriseName" label-width="200rpx">
					<u-input v-model="form.enterpriseName" placeholder="请输入企业名称" type="text" />
				</u-form-item>
				<u-form-item label="负责人*" prop="person" label-width="200rpx">
					<u-input v-model="form.person" placeholder="请输入负责人" type="text" />
				</u-form-item>
				<u-form-item label="手机号码*" prop="phone" label-width="200rpx">
					<u-input v-model="form.phone" placeholder="请输入手机号码" type="text" />
				</u-form-item>
				<u-form-item label="验证码*" prop="code" label-width="200rpx">
					<u-input placeholder="请输入验证码" v-model="form.code" type="text"></u-input>
					<u-button slot="right" type="success" size="mini" @click="getCode">{{ codeTips }}</u-button>
				</u-form-item>
				<u-form-item label="企业地区*" prop="region" label-width="200rpx">
					<u-input type="select" :select-open="pickerShow" v-model="form.region" placeholder="请选择省/市/区"
						@click="pickerShow = true"></u-input>
				</u-form-item>
				<u-form-item label="详细地址*" prop="detailedRegion" label-width="200rpx">
					<u-input v-model="form.detailedRegion" placeholder="请输入详细地址" type="text" />
				</u-form-item>
			</u-form>
		</view>
		<view class="title flex flex-ai-c">
			<view></view>
			<text>主营产品*</text>
		</view>
		<view class="list text-box">
			<u-form-item prop="intro">
				<u-input type="textarea" placeholder="请输入主营产品" v-model="form.intro" height="200" />
			</u-form-item>
		</view>
		<view class="title flex flex-ai-c">
			<view></view>
			<text>营业执照上传*</text>
		</view>
		<u-upload ref="uUpload" :action="action" :auto-upload="autoUpload" :file-list="fileList"
			:show-progress="showProgress" :deletable="deletable" :max-count="maxCount" :before-upload="beforeUpload"
			on-change="onChange">
		</u-upload>

		<button class="btn" @click="Submit()">确认上传</button>
		<u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
		<u-picker mode="region" v-model="pickerShow" @confirm="regionConfirm"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				errorType: ['message'],
				// 验证码时间
				codeTips: '',
				pickerShow: false,
				// 上次地址
				action: 'http://127.0.0.1:7001/upload',
				// 是否自动上传
				autoUpload: true,
				// 预置上传列表
				fileList: [],
				// 进度条和删除按钮
				showProgress: true,
				// 是否显示删除图片的按钮
				deletable: true,
				// 最大选择图片的数量
				maxCount: 1,
				// 表单数据
				form: {
					shopName: '',
					enterpriseName: "",
					person: "",
					phone: "",
					code: "",
					region: "",
					detailedRegion: "",
					intro: ""
				},
				rules: {
					shopName: [{
						required: true,
						message: '请输入店铺名称',
						trigger: ['change', 'blur'],
					}],
					enterpriseName: [{
						required: true,
						message: '请输入企业名称',
						trigger: ['change', 'blur'],
					}],
					person: [{
						required: true,
						message: '请输入负责人',
						trigger: ['change', 'blur'],
					}],
					phone: [{
							required: true,
							message: '请输入手机号',
							trigger: ['change', 'blur'],
						},
						{
							validator: (rule, value, callback) => {
								// 调用uView自带的js验证规则，详见：https://www.uviewui.com/js/test.html
								return this.$u.test.mobile(value);
							},
							message: '手机号码不正确',
							// 触发器可以同时用blur和change，二者之间用英文逗号隔开
							trigger: ['change', 'blur'],
						}
					],
					code: [{
							required: true,
							message: '请输入验证码',
							trigger: ['change', 'blur'],
						},
						{
							type: 'number',
							message: '验证码只能为数字',
							trigger: ['change', 'blur'],
						}
					],
					region: [{
						required: true,
						message: '请选择地区',
						trigger: 'change',
					}],
					detailedRegion: [{
						required: true,
						message: '请输入详细地址',
						trigger: ['change', 'blur'],
					}],
				}
			}
		},
		onLoad(params) {

		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			codeChange(text) {
				this.codeTips = text;
			},
			// 获取验证码
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码',
						mask: true
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						this.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			// 选择地区回调
			regionConfirm(e) {
				this.form.region = e.province.label + '-' + e.city.label + '-' + e.area.label;
			},
			// 上次前的回调
			beforeUpload(index, list) {

			},
			// 图片上传后的回调
			onChange(lists, name) {

			},
			// 确认上传
			Submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log('验证通过');
					} else {
						console.log('验证失败');
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		padding: 0 20rpx 20rpx;
	}

	.title {
		margin-bottom: 30rpx;
		margin-top: 45rpx;

		view {
			width: 11rpx;
			height: 41rpx;
			background: #0059B9;
			border-radius: 8rpx;
			margin-right: 10rpx;
		}

		text {
			font-family: SimHei;
			font-weight: 600;
			font-size: 35rpx;
			color: #1D1D1D;
		}
	}

	.list {
		background: #FFFFFF;
		border-radius: 17rpx;
		padding: 25rpx 20rpx 35rpx;

		.u-form-item {
			padding: 10rpx 0;
		}
	}

	.text-box {
		height: auto;
		min-height: 273rpx;
		color: #3E3E3E;
		line-height: 48rpx;
		padding: 27rpx 25rpx;
	}

	.btn {
		height: 90rpx;
		border-radius: 45rpx;
		color: #fff;
		background: linear-gradient(to top, #015EEA 0%, #00C0FA 100%);
	}
</style>